package com.ktjiaoyu.crm.web.controller;

import com.ktjiaoyu.crm.entity.Product;
import com.ktjiaoyu.crm.entity.Storage;
import com.ktjiaoyu.crm.service.IProductService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

@Controller
public class ProductController {
    @Resource
    private IProductService productService;

    @RequestMapping(value = "/basd/product")
    public String list(Model model, String prodName, String prodType,String proBatch,
                       @RequestParam(required = false, defaultValue = "1") int pageIndex){
        Sort sort = new Sort(Sort.Direction.ASC, "prodId");
        Pageable pageable = PageRequest.of(pageIndex-1, 5, sort);
        Page<Product> productPage = productService.findProNameAndProdTypeAndProBatch(prodName,prodType,proBatch,pageable);
        model.addAttribute("productPage", productPage);
        model.addAttribute("prodName", prodName);
        model.addAttribute("prodType", prodType);
        model.addAttribute("proBatch", proBatch);
        return "basd/product";
    }
}
